layui.use(['form','layer','laydate','table','laytpl'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;

    //添加验证规则
    form.verify({
        oldPwd: function (value, item) {
            if (value == '') {
                return "旧密码不能为空!";
            }
        },
        newPwd: function (value, item) {
            if(value.length < 6){
                return "密码长度不能小于6位";
            }
        },
        confirmPwd: function (value, item) {
            if (!new RegExp($("#newPwd").val()).test(value)) {
                return "两次输入密码不一致，请重新输入！";
            }
        }
    })

    //模糊查询
    form.on("submit(changePwd)", function (data) {
        var subData = {
            "loginName": $("#loginname").val(),
            "oldPwd": $("#oldPwd").val(),
            "newPwd": $("#newPwd").val()
        }

        //提交登录用户验证以及修改密码
        $.ajax({
            url: "/User/ProcessChangePwd",
            type: "post",
            data: subData,
            dataType: "json",
            success: function (data) {
                layer.msg(data.msg);

                setTimeout(function() {
                        if (data.code == 200) {
                            location.href = '/Sys/Index'; //跳转到系统首页(即让用户重新登录)
                        }
                    },
                    1000);

            }
        })

        return false;
    });

    $("#changePwd").click(function () {


        //layer.msg("hello");
        //var data = {
        //    "loginName": $("#loginname").val(),
        //    "oldPwd": $("#oldPwd").val(),
        //    "newPwd": $("#newPwd").val()
        //}

        ////提交登录用户验证以及修改密码
        //$.ajax({
        //    url: "/User/ProcessChangePwd",
        //    type: "post",
        //    data: data,
        //    dataType: "json",
        //    success: function (data) {
        //        layer.msg(data.msg);
        //    }
        //})

    });


})